package com.blog.aop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.druid.support.logging.LogFactory;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.logging.Logger;

/**
 *  HandlerInterceptor
 *  拦截器 在spring-mybaits里配置
 */
//@Component
public class LoginRequiredInterceptor implements HandlerInterceptor {

	//ThreadLocal<Long> aa=new ThreadLocal<Long>();
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
    	/*
    	System.out.println("class前,在"+o.toString()+"被调用");
    	Long startTime=System.currentTimeMillis();
    	aa.set(startTime);
    	
    	*/return true;
    }

    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
    	/*
    	 * System.out.println("class后,在"+o.toString()+"被调用");
    	 */
    }

    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
    	/*
    	System.out.println("class全部完成,在"+o.toString()+"被调用");
    	Long endTime=System.currentTimeMillis();
    	Long consumeTime = endTime-aa.get();
    	Logger.getLogger("newName").info("consume1 "+consumeTime);
    	LogFactory.getLog("newName").info("consume2 "+consumeTime);
    	*/
    }
}
